package com.example.tmxk.selvlet;

import com.example.tmxk.bean.NewsBean;
import com.example.tmxk.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class NewsServlet {
    @WebServlet("/news.jsp")
    public class newsServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws SecurityException, IOException, ServletException {
            // todo 获取分页页码参数
            //1.获取新闻信息
            NewsDao dao = new NewsDao();
            NewsDao newsDao = null;
            List<NewsBean> news = newsDao.getList();
            //2.传递新闻信息给前端页面
            req.setAttribute("news",news);
            //3.加载显示前端页面
            req.getRequestDispatcher("news,jsp").forward(req,resp);
        }
    }
}
